package com.twu.biblioteca.controller;

import com.google.common.collect.Lists;

import com.twu.biblioteca.enums.MapKey;

import java.util.List;
import java.util.Map;

public class BaseController implements Observable {
  private List<Observer> observerList = Lists.newArrayList();

  @Override
  public void register(Observer observer) {
    if (!observerList.contains(observer))
      observerList.add(observer);
  }

  @Override
  public int getObserverSize() {
    return observerList.size();
  }

  @Override
  public void update(Map<MapKey, Object> objectMap) {
    for (Observer observer : observerList) {
      observer.notify(objectMap);
    }
  }
}
